<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MY_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->helper("cookie");
		$this->load->helper('public');
		error_reporting(E_ALL);
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('user/createrole');
	}

	public function home() {
		$this->load->view('home/lib');
	}

	public function encode() {
		$str = authcode("1273Rxy", "encode", "redhome2013inHduAccount");
		echo "authcode: ".$str."<br>";
		$deCode = authcode($str, "DECODE", "redhome2013inHduAccount");
		echo "decode: ".$deCode."<br>";
	}

	public function json() {
		header('Content-type: text/json;charset=utf-8');
		$person = array(
			"stuID" => "11053428",
			"name" => "aside99"
			);

		$data = array(
			"status" => '1',
			"message" => "no_message",
			"data" => $person
			);
		
		echo json_encode($data);
	}

	protected function formed_json_data($status, $message, $data = array()) {
		if (count($data) == 0) {
			$arr = "";
		} else {
			$arr = "{";
			foreach($data as $key => $val) {
				$arr .= "\"{$key}\":\"{$val}\",";
			}
			$arr .= "}";
		}
		return "{\"status\":\"". $status ."\", \"message\": \"". $message ."\",\"data\":". $arr ."}";
	}

	public function ajaxtest() {
		$this->load->view("home/test");
	}

	//使用post方法测试api是否能使用
	function posttest() {
	    header("Content-type:text/html;charset=utf-8");
	    $targetUrl = "http://go.redhome.cc/passport/index.php/user/ajaxLogin";

	    $postData = "account=".urlencode("2deaHzWpjqPm/eNNTbNja4/2oQ9YuG9TqDe2SFQO6pXZFB4BCMNLQMH+XOM")."&password=".urlencode("b619e7h+Caw2LgG02zztrDfCg+dDL/FVxP8kgXtEOsj/joqH");

	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $targetUrl);
	    curl_setopt($ch, CURLOPT_HEADER, 1);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_POST, 1);
	    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
	    $content = curl_exec($ch);
	    curl_close($ch); 
	   	$content = htmlspecialchars($content);
	    echo $content;
	   
	}

	public function databasetest() {
		$this->load->model('bbs_model', 'bbs');
		$result = $this->bbs->selectMember();
		var_dump($result);

	}   
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */